<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
<meta name="description" content="Show all of the predefined kinds of arrowheads for links, which can be used by setting Shape.toArrow or Shape.fromArrow."/> 
<link rel="stylesheet" href="../assets/css/style.css"/> 
<!-- Copyright 1998-2021 by Northwoods Software Corporation. -->
<title>GoJS Arrowheads</title>
</head>

<body>
  <!-- This top nav is not part of the sample code -->
  <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
    <div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2">
      <div class="md:pl-4">
        <a class="text-white hover:text-white no-underline hover:no-underline
        font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
          <h1 class="mb-0 p-1 ">GoJS</h1>
        </a>
      </div>
      <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
        <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
          <path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path>
          <path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
        </svg>
      </button>
      <div id="topnavList" class="hidden lg:text-base sm:block items-center w-auto mt-0 text-white p-0 z-20">
        <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
           target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
           target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
        </ul>
      </div>
    </div>
    <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
  </nav>
  <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
    <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
    <!-- * * * * * * * * * * * * * -->
    <!-- Start of GoJS sample code -->
    
    <script src="../release/go.js"></script>
    <div class="p-4 w-full">
    <script id="code">
    function init() {
      var $ = go.GraphObject.make;  // for conciseness in defining templates

      var myDiagram =
        $(go.Diagram, "myDiagramDiv",  // create a Diagram for the DIV HTML element
          {
            isReadOnly: true,  // don't allow move or delete
            layout: $(go.CircularLayout,
              {
                radius: 100,  // minimum radius
                spacing: 0,   // circular nodes will touch each other
                nodeDiameterFormula: go.CircularLayout.Circular,  // assume nodes are circular
                startAngle: 270  // first node will be at top
              }),
            // define a DiagramEvent listener
            "LayoutCompleted": function(e) {
              // now that the CircularLayout has finished, we know where its center is
              var cntr = myDiagram.findNodeForKey("Center");
              cntr.location = myDiagram.layout.actualCenter;
            }
          });

      // construct a shared radial gradient brush
      var radBrush = $(go.Brush, "Radial", { 0: "#550266", 1: "#80418C" });

      // these are the nodes that are in a circle
      myDiagram.nodeTemplate =
        $(go.Node,
          $(go.Shape, "Circle",
            {
              desiredSize: new go.Size(28, 28),
              fill: radBrush, strokeWidth: 0, stroke: null
            }), // no outline
          {
            locationSpot: go.Spot.Center,
            click: showArrowInfo,  // defined below
            toolTip:  // define a tooltip for each link that displays its information
              $("ToolTip",
                $(go.TextBlock, { margin: 4 },
                  new go.Binding("text", "", infoString).ofObject())
              )
          }
        );

      // use a special template for the center node
      myDiagram.nodeTemplateMap.add("Center",
        $(go.Node, "Spot",
          {
            selectable: false,
            isLayoutPositioned: false,  // the Diagram.layout will not position this node
            locationSpot: go.Spot.Center
          },
          $(go.Shape, "Circle",
            { fill: radBrush, strokeWidth: 0, stroke: null, desiredSize: new go.Size(200, 200) }), // no outline
          $(go.TextBlock, "Arrowheads",
            { margin: 1, stroke: "white", font: "bold 14px sans-serif" })
        ));

      // all Links have both "toArrow" and "fromArrow" Shapes,
      // where both arrow properties are data bound
      myDiagram.linkTemplate =
        $(go.Link,  // the whole link panel
          { routing: go.Link.Normal },
          $(go.Shape,  // the link shape
            // the first element is assumed to be main element: as if isPanelMain were true
            { stroke: "gray", strokeWidth: 2 }),
          $(go.Shape,  // the "from" arrowhead
            new go.Binding("fromArrow", "fromArrow"),
            { scale: 2, fill: "#D4B52C" }),
          $(go.Shape,  // the "to" arrowhead
            new go.Binding("toArrow", "toArrow"),
            { scale: 2, fill: "#D4B52C" }),
          {
            click: showArrowInfo,
            toolTip:  // define a tooltip for each link that displays its information
              $("ToolTip",
                $(go.TextBlock, { margin: 4 },
                  new go.Binding("text", "", infoString).ofObject())
              )
          }
        );

      // collect all of the predefined arrowhead names
      var arrowheads = go.Shape.getArrowheadGeometries().toKeySet().toArray();
      if (arrowheads.length % 2 === 1) arrowheads.push("");  // make sure there's an even number

      // create all of the link data, two arrowheads per link
      var linkdata = [];
      var i = 0;
      for (var j = 0; j < arrowheads.length; j = j + 2) {
        linkdata.push({ from: "Center", to: i++, toArrow: arrowheads[j], fromArrow: arrowheads[j + 1] });
      }

      myDiagram.model =
        $(go.GraphLinksModel,
          { // this gets copied automatically when there's a link data reference to a new node key
            // and is then added to the nodeDataArray
            archetypeNodeData: {},
            // the node array starts with just the special Center node
            nodeDataArray: [{ category: "Center", key: "Center" }],
            // the link array was created above
            linkDataArray: linkdata
          });
    }

    // a conversion function used to get arrowhead information for a Part
    function infoString(obj) {
      var part = obj.part;
      if (part instanceof go.Adornment) part = part.adornedPart;
      var msg = "";
      if (part instanceof go.Link) {
        var link = part;
        msg = "toArrow: " + link.data.toArrow + ";\nfromArrow: " + link.data.fromArrow;
      } else if (part instanceof go.Node) {
        var node = part;
        var link = node.linksConnected.first();
        msg = "toArrow: " + link.data.toArrow + ";\nfromArrow: " + link.data.fromArrow;
      }
      return msg;
    }

    // a GraphObject.click event handler to show arrowhead information
    function showArrowInfo(e, obj) {
      var msg = infoString(obj);
      if (msg) {
        var status = document.getElementById("myArrowheadInfo");
        if (status) status.textContent = msg;
      }
    }
    window.addEventListener('DOMContentLoaded', init);
  </script>

<div id="sample">
  <!-- The DIV for the Diagram needs an explicit size or else we won't see anything.
       Also add a border to help see the edges. -->
  <div id="myDiagramDiv" style="border: solid 1px black; width:600px; height:500px"></div>
  <div id="myArrowheadInfo" style="color:red"></div>
  <p>
    This sample displays all predefined GoJS arrowheads.
    Select or hover over a Node or its Link to see the names of the arrowheads on the Link.
  </p>
  <p>
    Each Link shows two arrowheads.
    The Link template has a Shape whose <a>Shape.toArrow</a> property is bound to an arrowhead name.
    A different Shape in the template has its <a>Shape.fromArrow</a> property bound to a different arrowhead name.
    Each arrowhead has been scaled up to make it more easily visible.
  </p>
  <p>
    See the definitions of all these arrowheads in the file: <a href="../extensions/Arrowheads.js" target="_blank">Arrowheads.js</a>.
  </p>
  <p>
    For predefined shape geometries, see the <a href="shapes.html">Shapes</a> sample.
  </p>
</div>
    </div>
    <!-- * * * * * * * * * * * * * -->
    <!--  End of GoJS sample code  -->
  </div>
</body>
<!--  This script is part of the gojs.net website, and is not needed to run the sample -->
<script src="../assets/js/goSamples.js"></script>
</html>
